package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseSaleAttr;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.service.BaseSaleAttrService;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 🐱🐱🐱
 * @Date: 2025/8/18 20:40
 * @Description:
 **/
@Api(tags = "spu商品管理")
@RestController
@RequestMapping("admin/product")
public class SpuManageController {

    @Resource
    private ManageService manageService;

    @Resource
    private BaseSaleAttrService baseSaleAttrList;

    @ApiOperation("spu查询列表")
    @GetMapping("{page}/{size}")
    public Result getSpuInfoPage(@PathVariable Long page,
                                 @PathVariable Long size,
                                 SpuInfo spuInfo){
        Page<SpuInfo> spuInfoPage = new Page<>(page, size);
        IPage<SpuInfo> spuInfoIList = manageService.getSpuInfoPage(spuInfoPage,spuInfo);
        return Result.ok(spuInfoIList);
    }

    @ApiOperation("查询基本的销售属性列表")
    @GetMapping("baseSaleAttrList")
    public Result baseSaleAttrList(){
       List<BaseSaleAttr> list = manageService.baseSaleAttrList();
       return Result.ok(list);
    }

    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){

        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }


}
